import chineseholiday.domain.holiday.Holiday;
import chineseholiday.domain.holiday.HolidayGateWay;
import chineseholiday.infrastructure.holiday.HolidayGateWayImpl;

import java.time.LocalDate;

/**
 * @author 陈浩
 * @date 2021/8/14 14:17
 */
public class Main {

    public static void main(String[] args) throws Exception {
        System.out.println(count(LocalDate.of(2021,6,11), 8));
    }

    public static LocalDate count(LocalDate time, int days) throws Exception {
        HolidayGateWay gateWay = new HolidayGateWayImpl();
        LocalDate date = time.plusDays(1);
        int count = 0;
        boolean b = true;
        while (b) {
            Holiday holiday = gateWay.getDay(date);
            if (holiday == null) {
                boolean weekend = gateWay.isWeekend(date);
                if (weekend) {
                    date = date.plusDays(1);
                    continue;
                }
                count++;
                if (days == count) {
                    b = false;
                } else {
                    date = date.plusDays(1);
                }
                continue;
            }

            if (!holiday.getHoliday()) {
                count++;
                if (days == count) {
                    b = false;
                } else {
                    date = date.plusDays(1);
                }
                continue;
            }

            int size = holiday.getNextDay().size();
            date = date.plusDays(size + 1);

        }

        return date;
    }


}
